import axios from 'axios'
import store from '@/store'
axios.defaults.baseURL = 'http://ttapi.research.itcast.cn/'
// 设置请求拦截器携带token
axios.interceptors.request.use(
  function(config) {
    if (store.state.userToken && store.state.userToken.token) {
      config.headers.Authorization = `Bearer ${store.state.userToken.token}`
    }
    return config
  },
  error => {
    // 错误处理中间件
    return Promise.reject(error)
  }
)

export default axios
